package com.jy.api.domain;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang.StringUtils;

/**
 * 威富通查询订单结果对象
 */
@Data
@XStreamAlias("xml")
@ToString
public class SwiftPassPaymentQueryBaseResult extends SwiftPassBaseResult {
    @XStreamAlias("result_code")
    private String resultCode;

    @XStreamAlias("mch_id")
    private String mchId;

    @XStreamAlias("device_info")
    private String deviceInfo;

    @XStreamAlias("nonce_str")
    private String nonceStr;

    @XStreamAlias("err_code")
    private String errCode;

    @XStreamAlias("err_msg")
    private String errMsg;

    @XStreamAlias("trade_state")
    private String tradeState;


    /**
     * @return 是否需要继续轮询支付结果
     */
    @Override
    public boolean isNeedQuery() {
        return !isSuccess() && !isFailed();
    }

    @Override
    public boolean isFailed() {
        if (StringUtils.isNotEmpty(tradeState) && (tradeState.equalsIgnoreCase("REVOKED") || tradeState.equalsIgnoreCase("REVERSE") || tradeState.equalsIgnoreCase("PAYERROR"))) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean isSuccess() {
        if (StringUtils.isNotEmpty(tradeState) && tradeState.equalsIgnoreCase("SUCCESS")) {
            return true;
        } else {
            return false;
        }
    }

}
